package com.gxsyh.nantie.statements.management.provider.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxsyh.nantie.commons.dto.PageHelpDTO;
import com.gxsyh.nantie.commons.dto.ResponseResult;
import com.gxsyh.nantie.statements.management.provider.domain.TbDepartment;
import com.gxsyh.nantie.statements.management.provider.domain.UserOrderCount;
import com.gxsyh.nantie.statements.management.provider.domain.UserOrderInfo;
import com.gxsyh.nantie.statements.management.provider.service.TbDepartmentService;
import com.gxsyh.nantie.statements.management.provider.service.UserOrderCountService;
import com.gxsyh.nantie.statements.management.provider.service.UserOrderInfoService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class RailwayStatementController {

    @Resource
    private UserOrderInfoService userOrderInfoService;

    @Resource
    private UserOrderCountService userOrderCountService;

    @Resource
    private TbDepartmentService tbDepartmentService;


    /**
     * 获取 用户个人订单 列表
     * @param pageNum,userId
     * @return
     */
    @GetMapping(value = "/statements/railway/user/{pageNum}")
    public ResponseResult<PageHelpDTO> RailwayUserList(@PathVariable int pageNum, @RequestParam long userId){
        PageHelper.startPage(pageNum,5);
        PageInfo<UserOrderInfo> pageInfo=new PageInfo<>(userOrderInfoService.selectUserOrderInfo(userId));
        List<UserOrderInfo> userOrderInfoList = pageInfo.getList();
        PageHelpDTO pageHelpDTO=new PageHelpDTO();
        pageHelpDTO.setPages(pageInfo.getPages());
        pageHelpDTO.setTotal(pageInfo.getTotal());
        pageHelpDTO.setData(userOrderInfoList);
        return new ResponseResult<>(200,"用户订单报表",pageHelpDTO);
    }

    /**
     * 获取 班组 财务列表
     * @param pageNum,classId
     * @return
     */
    @GetMapping(value = "/statements/railway/class/{pageNum}")
    public ResponseResult<PageHelpDTO> RailwayClassList(@PathVariable int pageNum, @RequestParam long departmentId){
        PageHelper.startPage(pageNum,5);
        PageInfo<UserOrderCount> pageInfo=new PageInfo<>(userOrderCountService.getClassStatement(departmentId));
        List<UserOrderCount> userOrderCountList = pageInfo.getList();
        PageHelpDTO pageHelpDTO=new PageHelpDTO();
        pageHelpDTO.setPages(pageInfo.getPages());
        pageHelpDTO.setTotal(pageInfo.getTotal());
        pageHelpDTO.setData(userOrderCountList);
        return new ResponseResult<>(200,"班组报表",pageHelpDTO);
    }

    /**
     * 获取 车队 财务列表
     * @param pageNum,teamId
     * @return
     */
    @GetMapping(value = "/statements/railway/team/{pageNum}")
    public ResponseResult<PageHelpDTO> RailwayTeamList(@PathVariable int pageNum, @RequestParam long departmentId){
        PageHelper.startPage(pageNum,5);
        PageInfo<UserOrderCount> pageInfo=new PageInfo<>(userOrderCountService.getTeamStatement(departmentId));
        List<UserOrderCount> userOrderCountList = pageInfo.getList();
        PageHelpDTO pageHelpDTO=new PageHelpDTO();
        pageHelpDTO.setPages(pageInfo.getPages());
        pageHelpDTO.setTotal(pageInfo.getTotal());
        pageHelpDTO.setData(userOrderCountList);
        return new ResponseResult<>(200,"车队报表",pageHelpDTO);
    }

    /**
     * 获取 车间 财务列表
     * @param pageNum,teamId
     * @return
     */
    @GetMapping(value = "/statements/railway/workshop/{pageNum}")
    public ResponseResult<PageHelpDTO> RailwayWorkshopList(@PathVariable int pageNum, @RequestParam long departmentId){
        PageHelper.startPage(pageNum,5);
        PageInfo<UserOrderCount> pageInfo=new PageInfo<>(userOrderCountService.getWorkshopStatement(departmentId));
        List<UserOrderCount> userOrderCountList = pageInfo.getList();
        PageHelpDTO pageHelpDTO=new PageHelpDTO();
        pageHelpDTO.setPages(pageInfo.getPages());
        pageHelpDTO.setTotal(pageInfo.getTotal());
        pageHelpDTO.setData(userOrderCountList);
        return new ResponseResult<>(200,"车间报表",pageHelpDTO);
    }

    /**
     * 获取 车段 财务列表
     * @param pageNum,teamId
     * @return
     */
    @GetMapping(value = "/statements/railway/segment/{pageNum}")
    public ResponseResult<PageHelpDTO> RailwayVehicleSegmentList(@PathVariable int pageNum, @RequestParam long departmentId){
        PageHelper.startPage(pageNum,5);
        PageInfo<UserOrderCount> pageInfo=new PageInfo<>(userOrderCountService.getVehicleSegmentStatement(departmentId));
        List<UserOrderCount> userOrderCountList = pageInfo.getList();
        PageHelpDTO pageHelpDTO=new PageHelpDTO();
        pageHelpDTO.setPages(pageInfo.getPages());
        pageHelpDTO.setTotal(pageInfo.getTotal());
        pageHelpDTO.setData(userOrderCountList);
        return new ResponseResult<>(200,"车段报表",pageHelpDTO);
    }


    /**
     * 获取 部门的所有次级部门
     * @param pageNum,teamId
     * @return
     */
    @GetMapping(value = "/statements/department/{pageNum}")
    public ResponseResult<PageHelpDTO> DepartmentList(@PathVariable int pageNum, @RequestParam long departmentId){
        PageHelper.startPage(pageNum,5);
        PageInfo<TbDepartment> pageInfo=new PageInfo<>(tbDepartmentService.selectAllWorkshopSubordinate(0,departmentId));
        List<TbDepartment> tbDepartmentList = pageInfo.getList();
        PageHelpDTO pageHelpDTO=new PageHelpDTO();
        pageHelpDTO.setPages(pageInfo.getPages());
        pageHelpDTO.setTotal(pageInfo.getTotal());
        pageHelpDTO.setData(tbDepartmentList);
        return new ResponseResult<>(200,"获取车间的所有班组",pageHelpDTO);
    }




}
